package com.chenggcode.simple.json;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * @author Chenggcode
 * @date 2025/7/3 13:44
 */
@Setter
@Getter
public class JsonInfo {
    private String name;
    private Integer age;
    private Map<String, Object> address;
    private String emptyInfo;

    private static void fastjson2(JsonInfo jsonInfo) {
        // Fastjson2相关代码
        String jsonString = JSON.toJSONString(jsonInfo);
        System.out.println("Fastjson2序列化结果: " + jsonString);
    }

    private static void jackson(JsonInfo jsonInfo) {
        // Jackson相关代码
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String jsonString = objectMapper.writeValueAsString(jsonInfo);
            System.out.println("Jackson序列化结果: " + jsonString);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        JsonInfo jsonInfo = new JsonInfo();
        jsonInfo.setName("chenggcode");
        jsonInfo.setAge(0);
        jsonInfo.setAddress(Map.of("city", "Beijing", "country", "China"));
        fastjson2(jsonInfo);
        jackson(jsonInfo);
    }
}
